package com.gp.learn.ssm.base.system.controller;

import com.gp.learn.ssm.base.core.mybaits.model.ResultBody;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 测试用户权限
 */
@Controller
public class TestUserRoleController {

    @ResponseBody
    @RequestMapping("/sayHello")
    public String sayHello() {
        return "sayHello";
    }

    @ResponseBody
    @RequestMapping("/playBall")
    public String playBall() {
        return "play ball";
    }

    @ResponseBody
    @RequestMapping("/api/getUserInfo")
    public ResultBody getUerInfo() {
        //这里会做解析jwt操作，获取jwt中的用户名
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        ResultBody resultBody = new ResultBody();
        resultBody.data(authentication);
        return resultBody;
    }
}
